@REM ==================================================
@REM
@REM                  CleanProjectDir
@REM
@REM   This script recursively cleans the project's
@REM   directory from misc unnecessary files that
@REM   should never be committed to VCS.
@REM   If you specify the "force" parameter
@REM   then there will be no confirmations.
@REM
@REM                © 2012 by Xcentric
@REM ==================================================

@echo off
set ForceClean=force
if /I not "%1" == "%ForceClean%" (
  @echo Press any key to start cleaning in the project's directory!
  @pause > NUL
)

REM Deleting unnecessary files:
del /F /S /Q *.#??
del /F /S /Q *.$*
del /F /S /Q *.~bdsgroup
del /F /S /Q *.~bdsproj
del /F /S /Q *.~bpg
del /F /S /Q *.~cpp
del /F /S /Q *.~ddp
del /F /S /Q *.~dfm
del /F /S /Q *.~dpk
del /F /S /Q *.~dpr
del /F /S /Q *.~dproj
del /F /S /Q *.~dsk
del /F /S /Q *.~h
del /F /S /Q *.~hpp
del /F /S /Q *.~nfm
del /F /S /Q *.~pas
del /F /S /Q *.~xfm
del /F /S /Q *.bak
del /F /S /Q *.cbk
del /F /S /Q *.cfg
del /F /S /Q *.csm
del /F /S /Q *.dcpil
del /F /S /Q *.dcu
del /F /S /Q *.dcuil
del /F /S /Q *.ddp
del /F /S /Q *.dof
del /F /S /Q *.dsk
del /F /S /Q *.fts
del /F /S /Q *.gex
del /F /S /Q *.gid
del /F /S /Q *.identcache
del /F /S /Q *.il*
del /F /S /Q *.kwf
del /F /S /Q *.local
del /F /S /Q *.map
del /F /S /Q *.md
del /F /S /Q *.obj
del /F /S /Q *.pdb
del /F /S /Q *.rsm
del /F /S /Q *.tds
del /F /S /Q *.tmp
del /F /S /Q *.tvsconfig

if /I "%1"=="%ForceClean%" goto ForceRemoveHistory

REM Delete or not history files?
@echo Do you want to delete all history files from "__history" folders? [Y/N]
set /P Choice=
set Yes=Y
if /I %Choice% == %Yes% (
:ForceRemoveHistory
  del /F /S /Q *.~*
  call rmhist.exe
)